--[[

	Auto Carry Talon plugin by JavaNoob
	v.0.3
	Credits for damage calculation goes to 
	-Dekaron2
	Some minor Credits go to 
	-Vertoi
	as this is based on his script

--]]

class 'Talon'

if myHero.charName ~= "Talon" then return end
 
local waittxt = {}
local calculationenemy = 1
local floattext = {"BURST + ULT + 3", "BURST + 3", "BURST + ULT", "BURST!"}
local killable = {}

-- RANGE SETTINGS --
local rangeQ = AutoCarry.MyHero.TrueRange -- Q
local rangeW = 725 -- W
local thetaW = 50
local rangeE = 700 -- E
local rangeR = 645 -- R

local ulted = false
local useE = false
local killLevel = 0

local ignite = nil
local DFGSlot, HXGSlot, BWCSlot, SheenSlot, TrinitySlot, LichBaneSlot, TMTSlot, RAHSlot, RNDSlot, STDSlot = nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil
local QREADY, WREADY, EREADY, RREADY, DFGREADY, HXGREADY, BWCREADY, IREADY, TMTREADY, RAHREADY, RNDREADY, STDREADY, BRKREADY = false, false, false, false, false, false, false, false, false, false, false, false, false

local Target = nil

local SkillQ, SkillW, SkillE, SkillR = nil,nil,nil,nil
		
function Talon:__init()	  
	----------
	AutoCarry.SkillsCrosshair.range = rangeW
	
		
	--IGNITE--
	if myHero:GetSpellData(SUMMONER_1).name:find("SummonerDot") then ignite = SUMMONER_1
	elseif myHero:GetSpellData(SUMMONER_2).name:find("SummonerDot") then ignite = SUMMONER_2
	else ignite = nil end
	
	SkillQ = AutoCarry.Skills:NewSkill(false, _Q, rangeQ, "Noxian Diplomacy", AutoCarry.SPELL_SELF, 0, true, true, 1.67, 240, 50, false)
	SkillW = AutoCarry.Skills:NewSkill(false, _W, rangeW, "Rake", AutoCarry.SPELL_CONE, 0, false, false, 1.67, rangeW, thetaW, false)
	SkillE = AutoCarry.Skills:NewSkill(false, _E, rangeE, "Cutthroat", AutoCarry.SPELL_TARGETED, 0, false, false, 1, 240, 50, false)
	SkillR = AutoCarry.Skills:NewSkill(false, _R, rangeR, "Shadow Assault", AutoCarry.SPELL_CIRCLE, 0, false, false, 1.67, 240, 50, false)
	   
end

function Talon:OnTick()
		
		useE = Menu.autoE
		
		-- GET THE TARGET --
		if AutoCarry.Crosshair:GetTarget() ~= nil then Target = AutoCarry.Crosshair:GetTarget() end
	   
		-- AUTOPOTION --
		--if Menu.potion and (myHero.health / myHero.maxHealth <= 0.25) then
		--		CastItem(2003)
		--end
		
		dmgCalculation()
		
		
		if AutoCarry.MainMenu.AutoCarry and Target ~= nil then
			--KS MODE--
			for i=1, heroManager.iCount do
				local enemy = heroManager:GetHero(i)
				local burstRange = rangeQ;
				if EREADY and Menu.burstE or Menu.autoE then burstRange = rangeE end
				if ValidTarget(enemy, burstRange) then
					if killable[i] == 4 or (not Menu.defensive and killable[i] == 3) then
						Target = enemy
						useE = true
						killLevel = killable[i]
					end
				end
			end
			
			-- COMBO -- 
			doCombo() 
		end
		igniteCheck()
		-- USE W ON MINIONS (LANE CLEAR HOTKEY) --
		if AutoCarry.MainMenu.LaneClear then wMinions() end
		-- HARASS --
		if Menu.harass then harass() end
		-- ULTIMATE WHEN KILLABLE --
		if Menu.ultimate then useUlti() end
		
		if RREADY == false then ulted = false end
end

function doCombo()
	--local targettt = AutoCarry.GetAttackTarget(true)
	
	if Target == nil then return end
	
	AutoCarry.Items:UseAll(Target)
	
	AutoCarry.Orbwalker:Orbwalk(Target)
	SkillQ:Cast(Target)
	SkillW:Cast(Target) 
	if useE and not ValidTarget(Target, rangeQ) and ValidTarget(Target, rangeE) and not (Target.health < calcW(Target) and WREADY) and EREADY then
		SkillE:Cast(Target)
	end
end

function calcR(tar)
	if not Menu.ultimate then return 0 end
	dammm = getDmg("R", tar, myHero)
	if not Menu.defensive then
		if not ulted then dammm = dammm * 2 end
	else
		if ulted then dammm = 0 end
	end
	return dammm
end

function calcW(tar)
	dmg = getDmg("W",tar,myHero)
	if EREADY or GetDistance(tar) < (rangeW - 100) then
		dmg = dmg * 2
	end
	return dmg
end

function igniteCheck()
        if Menu.autoIgnite == true then
                local ignitedmg = 0            
                if IREADY then
                        for i = 1, heroManager.iCount, 1 do
                        local enemyhero = heroManager:getHero(i)
                                if ValidTarget(enemyhero) then
                                        ignitedmg = 50 + 20 * myHero.level
                                        if enemyhero ~= nil and enemyhero.team ~= myHero.team and not enemyhero.dead and enemyhero.visible and GetDistance(enemyhero) < 600 and enemyhero.health <= ignitedmg then
                                                CastSpell(ignite, enemyhero)
                                        end
                                end
                        end
                end              
        end        
end

function useUlti()
	if Target ~= nil then
		if Menu.burstUlt then
			local combLevel = calcTotalDmg(Target)
			--print(combLevel)
			if (combLevel == 4 or (not Menu.defensive and combLevel == 3)) and RREADY and GetDistance(Target) < rangeR  then
				SkillR:Cast(Target)
			end
		else
			--print(Target.health - calcR(Target))
			if RREADY and GetDistance(Target) < rangeR and Target.health < calcR(Target) then
				SkillR:Cast(Target)
			end
		end
	end
end

function harass()
	local targett = AutoCarry.GetAttackTarget(true)
	if ValidTarget(targett, rangeW) and WREADY then CastSpell(_W, targett) end
end

function wMinions()
	for index, minion in pairs(AutoCarry.EnemyMinions().objects) do
		if ValidTarget(minion, rangeW) and WREADY then
			CastSpell(_W, minion)  
		end
	end
end

function wLastHit()
	for index, minion in pairs(AutoCarry.EnemyMinions().objects) do
		if ValidTarget(minion, rangeW) and WREADY then
			if minion.health <= getDmg("W", minion, myHero) then
				CastSpell(_W, minion)  
			end
		end
	end
end

function PluginOnDraw()
	if ValidTarget(Target) then
	DrawText("Targetting: " .. Target.charName, 18, 650, 25, 0xFFFF0000)
	DrawCircle(Target.x, Target.y, Target.z, 100, 0x099B2299)
	end
	for i=1, heroManager.iCount do
	local enemydraw = heroManager:GetHero(i)
		if ValidTarget(enemydraw) then
			if killable[i] == 1 then
				for j=0, 10 do
					DrawCircle(enemydraw.x, enemydraw.y, enemydraw.z, 100+j*0.8, 0x099B2299)
				end
			end
			if killable[i] == 2 then
				for j=0, 10 do
					DrawCircle(enemydraw.x, enemydraw.y, enemydraw.z, 100+j*0.8, 0x099B2299)
				end
			end
			if killable[i] ==3  then
				DrawCircle(enemydraw.x, enemydraw.y, enemydraw.z, 100, 0x099B2299)
			end
			if killable[i] ==4  then
				DrawCircle(enemydraw.x, enemydraw.y, enemydraw.z, 100, 0xFFFFFF00)
			end
			if killable[i] ~= 0 then
					PrintFloatText(enemydraw,0,floattext[killable[i]])
			end
		end
	end
end

function skillState()
        local rData = myHero:GetSpellData(_R)
        if rData.name == "talonshadowassaulttoggle" then ulted = true end
        if rData.name == "TalonShadowAssault" then ulted = false end
       
end

function dmgCalculation()
	DFGSlot, HXGSlot, BWCSlot, SheenSlot, TrinitySlot, LichBaneSlot, BRKSlot, TMTSlot, RAHSlot, RNDSlot, STDSlot = GetInventorySlotItem(3128), GetInventorySlotItem(3146), GetInventorySlotItem(3144), GetInventorySlotItem(3057), GetInventorySlotItem(3078), GetInventorySlotItem(3100), GetInventorySlotItem(3153), GetInventorySlotItem(3077), GetInventorySlotItem(3074), GetInventorySlotItem(3143), GetInventorySlotItem(3131)
	QREADY = (SkillQ.Ready)
	WREADY = (SkillW.Ready)
	EREADY = (SkillE.Ready)
	RREADY = (SkillR.Ready)
	DFGREADY = (DFGSlot ~= nil and myHero:CanUseSpell(DFGSlot) == READY)
	HXGREADY = (HXGSlot ~= nil and myHero:CanUseSpell(HXGSlot) == READY)
	BWCREADY = (BWCSlot ~= nil and myHero:CanUseSpell(BWCSlot) == READY)
	BRKREADY = (BRKSlot ~= nil and myHero:CanUseSpell(BRKSlot) == READY)
	TMTREADY = (TMTSlot ~= nil and myHero:CanUseSpell(TMTSlot) == READY)
	RAHREADY = (RAHSlot ~= nil and myHero:CanUseSpell(RAHSlot) == READY)
	RNDREADY = (RNDSlot ~= nil and myHero:CanUseSpell(RNDSlot) == READY)
	STDREADY = (STDSlot ~= nil and myHero:CanUseSpell(STDSlot) == READY)
	IREADY = (ignite ~= nil and myHero:CanUseSpell(ignite) == READY)
	for i=1, heroManager.iCount do
	local enemy = heroManager:GetHero(i)
		if ValidTarget(enemy) then
			killable[i] = calcTotalDmg(enemy)
		end
	end -- end of for loop
 
end -- end of dmgCalculation() function

function calcTotalDmg(enemy)
	local dfgdamage, hxgdamage, bwcdamage, ignitedamage, Sheendamage, Trinitydamage, LichBanedamage  = 0, 0, 0, 0, 0, 0, 0
	local pdamage = getDmg("P",enemy,myHero)
	local qdamage = getDmg("Q",enemy,myHero)
	local edamage = getDmg("E",enemy,myHero)
	local rdamage = calcR(enemy)
	local wdamage = getDmg("W",enemy,myHero)
	local hitdamage = getDmg("AD",enemy,myHero)
	local dfgdamage = (DFGSlot and getDmg("DFG",enemy,myHero) or 0)
	local hxgdamage = (HXGSlot and getDmg("HXG",enemy,myHero) or 0)
	local bwcdamage = (BWCSlot and getDmg("BWC",enemy,myHero) or 0)
	local ignitedamage = (ignite and getDmg("IGNITE",enemy,myHero) or 0)
	local onhitdmg = (SheenSlot and getDmg("SHEEN",enemy,myHero) or 0)+(TrinitySlot and getDmg("TRINITY",enemy,myHero) or 0)+(LichBaneSlot and getDmg("LICHBANE",enemy,myHero) or 0)+(IcebornSlot and getDmg("ICEBORN",enemy,myHero) or 0)  
	local onspelldamage = (LiandrysSlot and getDmg("LIANDRYS",enemy,myHero) or 0)+(BlackfireSlot and getDmg("BLACKFIRE",enemy,myHero) or 0)
	local combo1 =  onspelldamage + pdamage + onhitdmg + (hitdamage * 3) + ignitedamage
	local combo2 = onspelldamage + pdamage + onhitdmg + (hitdamage * 3) + ignitedamage
	local combo3 = onspelldamage + pdamage + onhitdmg + hitdamage + ignitedamage
	local combo4 = onspelldamage + pdamage + onhitdmg + hitdamage + ignitedamage
	if QREADY then
		combo1 = combo1 + qdamage
		combo2 = combo2 + qdamage
		combo3 = combo3 + qdamage
		combo4 = combo4 + qdamage
	end
	if EREADY then
		combo1 = combo1 + edamage
		combo2 = combo2 + edamage
		combo3 = combo3 + edamage
		combo4 = combo4 + edamage
	end
	if WREADY then
		combo1 = combo1 + wdamage
		combo2 = combo2 + wdamage
		combo3 = combo3 + wdamage
		combo4 = combo4 + wdamage
	end
	if RREADY then
		combo1 = combo1 + rdamage
		--combo2 = combo2 + rdamage
		combo3 = combo3 + rdamage
		--combo4 = combo4 + rdamage
	end
	if HXGREADY then              
		combo1 = combo1 + hxgdamage    
		combo2 = combo2 + hxgdamage
		combo3 = combo3 + hxgdamage
		combo4 = combo4 + hxgdamage
	end
	if BWCREADY then
		combo1 = combo1 + bwcdamage
		combo2 = combo2 + bwcdamage
		combo3 = combo3 + bwcdamage
		combo4 = combo4 + bwcdamage
	end
	if DFGREADY then        
		combo1 = combo1 + dfgdamage            
		combo2 = combo2 + dfgdamage
		combo3 = combo3 + dfgdamage
		combo4 = combo4 + dfgdamage
	end                                                
	if IREADY then
		combo1 = combo1 + ignitedamage
		combo2 = combo2 + ignitedamage
		combo3 = combo3 + ignitedamage
		combo4 = combo4 + ignitedamage
	end
	if combo4 >= enemy.health then
		return 4
	elseif combo3 >= enemy.health then
		return 3                                        
	elseif combo2 >= enemy.health then
		return 2
	elseif combo1 >= enemy.health then
		return 1
	end
	return 0
end

Menu = AutoCarry.Plugins:RegisterPlugin(Talon(), "Talon")

Menu:addParam("harass", "Auto Harass", SCRIPT_PARAM_ONKEYTOGGLE, false, string.byte("Z")) -- harass --
Menu:addParam("potion", "Auto use potions", SCRIPT_PARAM_ONOFF, false) -- auto potion when less than 25% hp --
Menu:addParam("autoIgnite", "AutoIgnite", SCRIPT_PARAM_ONOFF, true) -- use ult defensively --
Menu:addParam("autoE", "Auto E", SCRIPT_PARAM_ONOFF, false) -- auto-E whenever it's up --
Menu:addParam("burstE", "Use E if enemy is killable by burst", SCRIPT_PARAM_ONOFF, true) -- use E if enemy is burstable --
Menu:addParam("ultimate", "Use ulti when killable", SCRIPT_PARAM_ONKEYTOGGLE, true, string.byte("N")) -- auto-ulti when killable --
Menu:addParam("defensive", "Only ult once", SCRIPT_PARAM_ONOFF, false) -- use ult defensively 
Menu:addParam("burstUlt", "Use ult mid-burst", SCRIPT_PARAM_ONOFF, true) -- use ult mid-burst 

-- PERMA SHOW --
Menu:permaShow("harass")
Menu:permaShow("ultimate")

--UPDATEURL=
--HASH=F3604CE352194A1553A063B84C238FF5
